# $FreeBSD$
#
# Provide support for Ubuntu related ports.
#
# Feature:	ubuntu
# Usage:	USES=ubuntu or USES=ubuntu:ARGS
# Valid ARGS:	snapshot
#
# 'snapshot' requires USE_AUTOTOOLS macro in Makefile.
#
# Variables, which can be set by the port:
#
# UBUNTU_RELEASE		- Version on which development is focusing
# UBUNTU_SNAPSHOT		- Format YYYMMDD (Y: year, M: month, D: day)
# USE_UBUNTU				- List of components
#
# MAINTAINER:	olivierd@FreeBSD.org

.if !defined(_INCLUDE_USES_UBUNTU_Mk)
_INCLUDE_USES_UBUNTU_Mk=	yes

_USE_UBUNTU_ALL=	autoconfhack ido libappindicator libdbusmenu \
	libindicate libindicator libunity

CPPFLAGS+=	-I${LOCALBASE}/include
LDFLAGS+=	-L${LOCALBASE}/lib

# Define in devel/libindicator
PLIST_SUB+=	INDICATOR_ABI="0.7"

autoconfhack_PRE_PATCH=	${FIND} ${WRKSRC} -name 'configure.ac' -type f \
	| ${XARGS} ${REINPLACE_CMD} -i '' 's|AM_CONFIG_HEADER|AC_CONFIG_HEADER|'

ido_LIB_DEPENDS=	libido3-0.1.so:${PORTSDIR}/x11-toolkits/ido

libappindicator_LIB_DEPENDS=	libappindicator3.so:${PORTSDIR}/devel/libappindicator
libappindicator_USE_UBUNTU_REQ=	libdbusmenu libindicator

libdbusmenu_LIB_DEPENDS=	libdbusmenu-glib.so:${PORTSDIR}/devel/libdbusmenu

libindicate_LIB_DEPENDS=	libindicate.so:${PORTSDIR}/devel/libindicate
libindicate_USE_UBUNTU_REQ=	libdbusmenu

libindicator_LIB_DEPENDS=	libindicator3.so:${PORTSDIR}/devel/libindicator
libindicator_USE_UBUNTU_REQ=	ido

libunity_LIB_DEPENDS=	libunity.so:${PORTSDIR}/devel/libunity
libunity_USE_UBUNTU_REQ=	libdbusmenu

.if defined(USE_UBUNTU)
# First of all expand all USE_UBUNTU_REQ recursively
.for component in ${_USE_UBUNTU_ALL}
.	for subcomp in ${${component}_USE_UBUNTU_REQ}
${component}_USE_UBUNTU_REQ+=${${subcomp}_USE_UBUNTU_REQ}
.	endfor
.endfor

# Then use already expanded USE_UBUNTU_REQ to expand USE_UBUNTU.
.for component in ${USE_UBUNTU}
.	if ${_USE_UBUNTU_ALL:M${component}} == ""
IGNORE=	cannot install: Unknown component ${component}
.	endif
_USE_UBUNTU+=	${${component}_USE_UBUNTU_REQ} ${component}
.endfor

# Remove duplicate components.
USE_UBUNTU=	${_USE_UBUNTU:O:u}

.for component in ${USE_UBUNTU}
.	if defined(${component}_BUILD_DEPENDS)
BUILD_DEPENDS+=	${${component}_BUILD_DEPENDS}
.	endif

.	if defined(${component}_LIB_DEPENDS)
LIB_DEPENDS+=	${${component}_LIB_DEPENDS}
.	endif

.	if defined(${component}_RUN_DEPENDS)
RUN_DEPENDS+=	${${component}_RUN_DEPENDS}
.	endif

.	if defined(${component}_CONFIGURE_ARGS)
CONFIGURE_ARGS+=${${component}_CONFIGURE_ARGS}
.	endif

.	if defined(${component}_PRE_PATCH)
UBUNTU_PRE_PATCH+=${${component}_PRE_PATCH}
.	endif
.endfor

.if defined(UBUNTU_PRE_PATCH)
pre-patch: ubuntu-pre-patch

ubuntu-pre-patch:
	${UBUNTU_PRE_PATCH}
.endif

ubuntu_ARGS?=	# empty

.if ${ubuntu_ARGS} == snapshot
# Version on which development is focusing
UBUNTU_RELEASE?=	14.10
UBUNTU_SNAPSHOT?=	20140814

BUILD_DEPENDS+= gnome-autogen.sh:${PORTSDIR}/devel/gnome-common

DISTNAME=	${PORTNAME}_${PORTVERSION}+${UBUNTU_RELEASE}.${UBUNTU_SNAPSHOT}.orig
WRKSRC=	${WRKDIR}/${PORTNAME}-${PORTVERSION}+${UBUNTU_RELEASE}.${UBUNTU_SNAPSHOT}

pre-configure:
	cd ${WRKSRC} && NOCONFIGURE=yes ${SH} ./autogen.sh

.endif	# end of ${ubuntu_ARGS} == snapshot

.endif	# end of defined(USE_UBUNTU)

.endif
